def get_order_no(name):
    result = [];
    with open('../case/软著代码去除空行和注释行/elk日志分析', encoding='utf-8', mode='r') as f:
        for line in f:
            # print(line)
            idx = line.find("参数:")
            l1 = line[idx + 3:-1]
            idx2 = l1.find(" ")
            result.append(l1[:idx2])
    return result


'''
获取单号：OO_SF_TCDB000961
源数据为： Mar 20, 2024 @ 04:34:26.451	msg:更改计费任务状态,参数:OO_SF_TCDB000961 @timestamp:Mar 20, 2024 @ 04:34:26.451 class:com.csair.psc.scmp.charging.controller.TsChargingTaskLogJobController:85 date:2024-03-20T04:33:45.052+08:00 traceId: level:INFO merAppId:scmp server:10.80.99.116 logType:S @version:01基础 thread:http-nio-9120-exec-8 channel:scmp_chg _id:ggJsWI4BTfBNOotUMvDx _type:_doc _index:scmp-2024-03 _score:01基础
'''


def get_chrgTask_sql(orders):
    sql_pref = "select t.charging_bill_no, t.contract_clause_no , t.task_status , t.create_time, t.update_time from ts_charging_task_log t where t.contract_clause_no in ("
    for order_no in orders:
        sql_pref = sql_pref + "'" + order_no + "',"
    return sql_pref[:len(sql_pref) - 1] + ");"


def get_contract_sql(orders):
    sql_pref = "select t.`NO` , t.status  from ts_contract_article t where t.`NO` in ("
    for order_no in orders:
        sql_pref = sql_pref + "'" + order_no + "',"
    return sql_pref[:len(sql_pref) - 1] + ");"


def set_chrgTask_status_sql(orders):
    sql_pref = "update ts_charging_task_log set task_status = 4 where charging_bill_no in ("
    for order_no in orders:
        sql_pref = sql_pref + "'" + order_no + "',"
    return sql_pref[:len(sql_pref) - 1] + ");"


if __name__ == '__main__':
    aa = get_order_no('PyCharm')
    bb = get_chrgTask_sql(aa)
    cc = get_contract_sql(aa)
    dd = set_chrgTask_status_sql(aa)
    print(bb)
    print(cc)
    print(dd)
